package com.yeskery.boot.log.record.starter.parser;

import com.yeskery.boot.log.record.starter.extend.IParseFunction;

/**
 * 默认自定方法服务接口实现
 * @author dushuangjiang
 * @date 2021-11-16 18:15
 */
public class DefaultFunctionServiceImpl implements IFunctionService {

    private final ParseFunctionFactory parseFunctionFactory;

    /**
     * 构造默认自定方法服务接口实现对象
     * @param parseFunctionFactory 自定义方法工厂
     */
    public DefaultFunctionServiceImpl(ParseFunctionFactory parseFunctionFactory) {
        this.parseFunctionFactory = parseFunctionFactory;
    }

    @Override
    public String apply(String functionName, String value) {
        IParseFunction function = parseFunctionFactory.getFunction(functionName);
        if (function == null) {
            return value;
        }
        return function.apply(value);
    }

    @Override
    public boolean beforeFunction(String functionName) {
        return parseFunctionFactory.isBeforeFunction(functionName);
    }
}
